/*
 * @Author: your name
 * @Date: 2021-04-22 14:49:58
 * @LastEditTime: 2021-04-22 16:10:58
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \chronic-back-end\module\healthyMod\service.go
 */
package healthMod

import (
	"chronic/common"
)

func addHealthData(patientId uint, input healthDataDto) (*Health, error) {
	db := common.UseDb()
	data := Health{PatientID: patientId, BodyWeight: input.BodyWeight, HeartRate: input.HeartRate, PressureShrink: input.PressureShrink, PressureExtend: input.PressureExtend, BloodSugar: input.BloodSugar, BloodLipidsSum: input.BloodLipidsSum, BloodLipidsGan: input.BloodLipidsGan}
	err := db.Save(&data).Error
	return &data, err
}

func findHealthDataHistory(patientId uint) ([]*Health, error) {
	db := common.UseDb()
	var datas []*Health
	err := db.Where("patient_id=?", patientId).Order("created_at desc").Find(&datas).Error
	return datas, err
}
